{%- macro _arg_url_for(endpoint, base) -%}
    {%- with kargs = base.copy() -%}
        {%- do kargs.update(kwargs) -%}
        {{ url_for(endpoint, **kargs) }}
    {%- endwith %}
{%- endmacro -%}

{%- macro render_pagination(
    pagination,
    endpoint=None,
    prev=('previous')|safe,
    next=('next')|safe,
    ellipses='…',
    args={},
    fragment='',
    class=''
) -%}
    {%- if fragment != '' and not fragment.startswith('#') -%}{%- set fragment = '#' + fragment %}{% endif -%}
    {% with url_args = {} %}
        {% do url_args.update(request.view_args if not endpoint else {}), url_args.update(request.args if not endpoint else {}), url_args.update(args) -%}
        {%- with endpoint = endpoint or request.endpoint -%}
        <nav class="pagination{% if class %} {{ class }}{% endif %}">
            {% if prev != None -%}
            <a class="pagination-previous"{% if not pagination.has_prev %} disabled {% endif %}href="{{ _arg_url_for(endpoint, url_args, page=pagination.prev_num) if pagination.has_prev else '#' }}{{ fragment }}">{{ prev }}</a>
            {%- endif -%}
            {% if next != None %}
            <a class="pagination-next"{% if not pagination.has_next %} disabled {% endif %}href="{{ _arg_url_for(endpoint, url_args, page=pagination.next_num) if pagination.has_next else '#' }}{{ fragment }}">{{ next }}</a>
            {%- endif %}
            <ul class="pagination-list">
                {% for page in pagination.iter_pages() -%}
                    {%- if page -%}
                        {%- if page != pagination.page %}
                <li><a class="pagination-link" href="{{ _arg_url_for(endpoint, url_args, page=page) }}{{ fragment }}">{{ page }}</a></li>
                        {%- else -%}
                <li><a class="pagination-link is-current" href="#">{{ page }}</a></li>
                        {%- endif %}
                    {%- elif ellipses != None -%}
                <li><span class="pagination-ellipsis">{{ ellipses }}</span></li>
                    {%- endif %}
                {%- endfor %}
            </ul>
        </nav>
        {%- endwith -%}
    {%- endwith -%}
{%- endmacro -%}